import java.text.SimpleDateFormat;

/**
 * Created by wh on 2017/8/26.
 */
public class Logger {
    private static int DEBUG = 0;
    private static int INFO = 1;
    private static int WARNING = 2;
    private static int ERROR = 3;

    private static int level = INFO;

    public static void debug(String s) {
        if (level <= DEBUG) {
            System.out.print(getTime());
            System.out.print(" [DEBUG] ");
            System.out.println(s);
        }
    }

    public static void info(String s) {
        if (level <= INFO) {
            System.out.print(getTime());
            System.out.print(" [INFO] ");
            System.out.println(s);
        }
    }

    public static void warning(String s) {
        if (level <= WARNING) {
            System.out.print(getTime());
            System.out.print(" [WARNING] ");
            System.out.println(s);
        }
    }

    public static void error(String s) {
        if (level <= ERROR) {
            System.out.print(getTime());
            System.out.print(" [ERROR] ");
            System.out.println(s);
        }
    }

    private static String getTime() {
        SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return time.format(new java.util.Date());
    }
}
